#include <stdio.h>

int htoi(char s[]);

int main()
{
    printf("%d\n", htoi("0x1f"));
    printf("%d\n", htoi("2F"));

    return 0;
}

int htoi(char s[])
{
    int i, n;

    n = 0;
    for (i = 0; s[i] != '\0'; ++i)
    {

        if (s[i] >= '0' && s[i] <= '9')
        {
            n = 16 * n + (s[i] - '0');
        }
        else if (s[i] >= 'A' && s[i] <= 'F')
        {
            n = 16 * n + (s[i] - 55);
        }
        else if (s[i] >= 'a' && s[i] <= 'f')
        {
            n = 16 * n + (s[i] - 87);
        }
    }
    return n;
}